package com.geotmt.billingcenter.modules.params.controller;

import com.geotmt.billingcenter.common.result.ResponseResult;
import com.geotmt.billingcenter.common.vo.params.*;
import com.geotmt.billingcenter.modules.params.service.ParamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Description PARAMS LIST
 * @Author      yanghanwei
 * @Mail        yanghanwei@geotmt.com
 * @Date        2019/3/21 11:16
 * @Version     v1
 **/
@RestController
@RequestMapping(value = "/bc/param")
@Api(value = "PARAMS LIST",tags = "PARAMS LIST")
public class ParamController {

    private static final Logger logger = LoggerFactory.getLogger(ParamController.class);

    @Resource
    private ParamService paramService;

    /**
     * 产品List
     * @return
     */
    @ApiOperation(value = "产品List")
    @RequestMapping(value = "/productList", method = RequestMethod.POST)
    public ResponseResult productList(){
        logger.info("查询产品List");
        List<Product> productList;
        try{
            productList = paramService.productList();
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.error("查询失败");
        }
        return ResponseResult.build(HttpServletResponse.SC_OK,"查询成功",productList,true);
    }

    /**
     * 客户List
     * @param forParam
     * @return
     */
    @ApiOperation(value = "客户List")
    @RequestMapping(value = "/companyList", method = RequestMethod.POST)
    public ResponseResult companyList(@RequestBody ForParam forParam){
        logger.info("查询客户List");
        List<Company> companyList;
        try{
            companyList = paramService.companyList(forParam.getProductCode());
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.error("查询失败");
        }
        return ResponseResult.build(HttpServletResponse.SC_OK,"查询成功",companyList,true);
    }

    /**
     * 用户List
     * @param forParam
     * @return
     */
    @ApiOperation(value = "用户List")
    @RequestMapping(value = "/userList", method = RequestMethod.POST)
    public ResponseResult userList(@RequestBody ForParam forParam){
        logger.info("查询用户List");
        List<Cuser> userList;
        try{
            userList = paramService.userList(forParam.getProductCode(), forParam.getCompanyId());
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.error("查询失败");
        }
        return ResponseResult.build(HttpServletResponse.SC_OK,"查询成功",userList,true);
    }

    /**
     * 内部接口List
     * @param forParam
     * @return
     */
    @ApiOperation(value = "内部接口List")
    @RequestMapping(value = "/innerIntegerList", method = RequestMethod.POST)
    public ResponseResult innerIntegerList(@RequestBody ForParam forParam){
        logger.info("查询内部接口List");
        List<InnerInterface> innerIntegerList;
        try{
            innerIntegerList = paramService.innerIntegerList(forParam.getProductCode(), forParam.getCompanyId(), forParam.getUserId());
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.error("查询失败");
        }
        return ResponseResult.build(HttpServletResponse.SC_OK,"查询成功",innerIntegerList,true);
    }


    /**
     * 数据源List
     * @return
     */
    @ApiOperation(value = "数据源List")
    @RequestMapping(value = "/dsList", method = RequestMethod.POST)
    public ResponseResult dsList(){
        logger.info("查询数据源List");
        List<DataSource> dsList;
        try{
            dsList = paramService.dsList();
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.error("查询失败");
        }
        return ResponseResult.build(HttpServletResponse.SC_OK,"查询成功",dsList,true);
    }

    /**
     * 外部接口List
     * @param dsId
     * @return
     */
    @ApiOperation(value = "外部接口List")
    @RequestMapping(value = "/outInterfaceList", method = RequestMethod.POST)
    public ResponseResult outInterfaceList(@ApiParam(value = "数据源id", name = "dsId") @RequestParam(value = "dsId",required = false) Integer dsId){
        logger.info("查询外部接口List");
        List<OutInterface> outInterfaceList;
        try{
            outInterfaceList = paramService.outInterfaceList(dsId);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.error("查询失败");
        }
        return ResponseResult.build(HttpServletResponse.SC_OK,"查询成功",outInterfaceList,true);
    }

}
